package com.example.administrator.hqq.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by admin on 2017/9/4.
 */

public class FragmentsAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragments;
    private List<String> titles;
    public FragmentsAdapter(FragmentManager fm, List<Fragment> mFragments,List<String> titles) {
        super(fm);
        this.mFragments = mFragments;
        this.titles=titles;
    }
    public FragmentsAdapter(FragmentManager fm, List<Fragment> mFragments) {
        super(fm);
        this.mFragments = mFragments;
    }


    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if (titles!=null)
        {
            return titles.get(position);
        }
        return super.getPageTitle(position);
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return super.getItemPosition(object);
    }
}
